<template>
  <div class='top_nav_box'>
    <div class="innerBox">
      <div class="left" @click='leftFn' v-if='!noleft'>
        <slot name='left'>
          <!-- slot中的结构是默认结构 -->
          <van-icon @click="back" name="arrow-left" />
        </slot>
      </div>
      <div class="middle">
        <slot name='middle'>
          <div @click='toSearch' class='divSearchBox'>
            <van-icon name="search" />
            搜一搜
          </div>
        </slot>
      </div>
      <div class="right" v-if='!noright'>
        <slot name='right'>
          <div>搜索</div>
        </slot>
      </div>
    </div>
  </div>
</template>
<script>
// @ is an alias to /src
export default {
  name: "topBar",
  props:{
    noleft:{
      default:false
    },
    noright:{
      default:false
    },
  },
  data() {
    return {};
  },
  methods: {
    leftFn(e){
      this.$emit('left',e)
    },
    back(){
      if(!this.$listeners.left){
        this.$router.back()
      }
      
    },
    toSearch(){
      if(!this.$listeners.middle){
        this.$router.push('/search')
      }
    }
  },
  components: {},
};
</script>
<style lang="less">
.top_nav_box{
  position: relative;
  height: 50px;
  .innerBox{
    position: fixed;
    display: flex;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
    height: 50px;
    align-items: center;
    text-align: center;
    justify-content: space-around;
    // >div{
    //   flex: 1;
    // }
    .left{
      width: 70px;
      text-align: left;
    }
    .middle{
      flex:auto;
      .divSearchBox{
        width: 100%;
        height: 30px;
        line-height: 30px;
        border-radius: 20px;
        border: 1px solid #eee;
        overflow: hidden;
        text-align: left;
        padding: 0 10px;
        box-sizing: border-box;
        background: #fff;
        font-size: 14px;
        color:rgb(187, 185, 185);
        .van-icon-search{
          vertical-align: middle;
          font-size: 19px;
        }
      }
    }
    .right{
      width:70px;
      text-align: right;
    }
  }
}
</style>